package com.zhl.hadoop.cases.phone;

import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Reducer;

import java.io.IOException;

/**
 * @program: demos
 * @description:
 * @author: 刘振华
 * @create: 2020-10-28 11:11
 **/
public class PhoneFlowReduce extends Reducer<Text, PhoneFlow,Text,Text> {

	@Override
	protected void reduce(Text key, Iterable<PhoneFlow> values, Context context) throws IOException, InterruptedException {
		int up = 0,down = 0,upAll = 0,downAll = 0;
		for (PhoneFlow info : values) {
			up += info.getUp();
			down += info.getDown();
			upAll += info.getUpAll();
			downAll += info.getDownAll();
		}
		context.write(key,new Text(up+"\t"+down+"\t"+upAll+"\t"+downAll));
	}
}
